package org.csy.generic.test00.demo01.myWork;

import java.beans.PropertyDescriptor;
import java.lang.reflect.Method;

/**
 * @author CSY
 * @date 2025 - 03 - 25
 */
public class People<T> {
    private T pet;

    public People(){}

    public People(T pet) {
        this.pet = pet;
    }

    public T getPet() {
        return pet;
    }

    public void setPet(T pet) {
        this.pet = pet;
    }

    public void shopping(){
        if(pet == null){
            throw new NullPointerException("宠物为空值！");
        }
        try {
            Class<?> clazz = pet.getClass();
            PropertyDescriptor propertyDescriptor = new PropertyDescriptor("type", clazz);
            Object invoke = propertyDescriptor.getReadMethod().invoke(pet);
            System.out.println("带着"+invoke+"逛街");
            if (pet instanceof Behavior){
                Method method = clazz.getMethod("shout");
                method.invoke(pet);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }

    }
}
